//生成时间:2022-08-15 09:17
var ehr={
    s_no:null,//工号
    Set_s_no:function(s_no){
        if(s_no.length<1 || s_no.length>20){
            return '工号的字数必须在1~20之间';
        }
        var reg=/^([A-Z]|[a-z]|\d)(\d{4,17}|(\d{4,17}[A-Z]\d{0,4}))|(^\d{18}$)|(^\d{17}(\d|X|x)$)$/;
        var patt=new RegExp(reg);
        if(!patt.test(s_no)){
            return '工号的格式不符合规定';
        }
        ehr.s_no=s_no.replace(/\'/g,"&apos;");
    },
    s_name:null,//姓名
    Set_s_name:function(s_name){
        if(s_name.length<0 || s_name.length>90){
            return '姓名的字数必须在0~90之间';
        }
        ehr.s_name=s_name.replace(/\'/g,"&apos;");
    },
    s_dept:null,//部门
    Set_s_dept:function(s_dept){
        if(s_dept.length<1 || s_dept.length>300){
            return '部门的字数必须在1~300之间';
        }
        ehr.s_dept=s_dept.replace(/\'/g,"&apos;");
    },
    s_sex:null,//性别
    Set_s_sex:function(s_sex){
        if(s_sex.length<1 || s_sex.length>20){
            return '性别的字数必须在1~20之间';
        }
        var area=["男","女"];
        if(area.indexOf(s_sex)){
            return '性别不在指定的范围内';
        }
        ehr.s_sex=s_sex.replace(/\'/g,"&apos;");
    },
    s_ingroup_date:null,//入集团日期
    Set_s_ingroup_date:function(s_ingroup_date){
        if(s_ingroup_date.length<1 || s_ingroup_date.length>20){
            return '入集团日期的字数必须在1~20之间';
        }
        var reg=/(^\d{4}\/([1-9]|1[1-2])\/([1-9]|[1-2][0-9]|3[0-1])$)|(^\d{4}\-(0[1-9]|1[0-2])\-(0[1-9]|[1-2][0-9]|3[0-1])$)/;
        var patt=new RegExp(reg);
        if(!patt.test(s_ingroup_date)){
            return '入集团日期的格式不符合规定';
        }
        ehr.s_ingroup_date=s_ingroup_date.replace(/\'/g,"&apos;");
    },
    s_tel:null,//手机号码
    Set_s_tel:function(s_tel){
        if(s_tel.length<1 || s_tel.length>20){
            return '手机号码的字数必须在1~20之间';
        }
        var reg=/\d{3}-\d{8}|\d{4}-\d{7}/;
        var patt=new RegExp(reg);
        if(!patt.test(s_tel)){
            return '手机号码的格式不符合规定';
        }
        ehr.s_tel=s_tel.replace(/\'/g,"&apos;");
    },
    s_position:null,//职位
    Set_s_position:function(s_position){
        if(s_position.length<1 || s_position.length>90){
            return '职位的字数必须在1~90之间';
        }
        ehr.s_position=s_position.replace(/\'/g,"&apos;");
    },
    s_level:null,//资位
    Set_s_level:function(s_level){
        if(s_level.length<1 || s_level.length>90){
            return '资位的字数必须在1~90之间';
        }
        var area=["员1","员2","员3","师1","师2","师3","师4","师5","师6","师7","师8","师9","师10","师11","师11","师12","师13","师14","师15","师16","师17","师18","师19","师20"];
        if(area.indexOf(s_level)){
            return '资位不在指定的范围内';
        }
        ehr.s_level=s_level.replace(/\'/g,"&apos;");
    },
    s_married:null,//婚姻状况
    Set_s_married:function(s_married){
        if(s_married.length<1 || s_married.length>20){
            return '婚姻状况的字数必须在1~20之间';
        }
        var area=["未婚","已婚"];
        if(area.indexOf(s_married)){
            return '婚姻状况不在指定的范围内';
        }
        ehr.s_married=s_married.replace(/\'/g,"&apos;");
    },
    s_city:null,//籍贯
    Set_s_city:function(s_city){
        if(s_city.length<1 || s_city.length>90){
            return '籍贯的字数必须在1~90之间';
        }
        ehr.s_city=s_city.replace(/\'/g,"&apos;");
    },
    s_company:null,//法人
    Set_s_company:function(s_company){
        if(s_company.length<1 || s_company.length>300){
            return '法人的字数必须在1~300之间';
        }
        ehr.s_company=s_company.replace(/\'/g,"&apos;");
    },
    UseForm: function (elem) {
        for (var key in ehr) {
            if (typeof ehr[key] == "function") {
                continue;//过滤方法
            }
            if (elem.querySelector("#" + key) ==null) {
                continue;//过滤不存在表单组件
            }
            var val = "";
            if(['INPUT','SELECT','TEXTAREA'].indexOf(elem.querySelector("#"+key).nodeName)>-1){;
                val=elem.querySelector("#"+key).value;
            };
            if(['IMG'].indexOf(elem.querySelector("#"+key).nodeName)>-1){;
                val=elem.querySelector("#"+key).src;
            };
            var res = ehr["Set_" + key](val);
            if (res) {
                return res;
            }
        }
        return null;
    },
    CreateFormdata: function () {
        var postData = new FormData();
        for (var key in ehr) {
            if (typeof ehr[key] == "function") {
                continue;//过滤方法
            }
            if (ehr[key] == null) {
                  continue;
            }
            postData.append(key, ehr[key]);
        }
        return postData;
    },
    CreateJson: function () {
        var json = {};
        for (var key in ehr) {
            if (typeof ehr[key] == "function") {
                continue;//过滤方法
            }
            if (ehr[key] == null) {
                  continue;
            }
            json[key] = ehr[key];
        }
        return json;
    }
}
